<?php 

// Bandeau supérieur de l'application
function menuSuperieur($choixMenu) {
	?>
    <div class="ui-grid-b" id="menu-top" >
        <?php
        
        ///////////////////////
        // Bouton ACCUEIL //
        ///////////////////////
        
        if ($choixMenu[0] != false) {?>     
            <a class="ui-block-a"  data-role="button" data-icon="home"  href="index.php?page=accueil" id="bouton-home" >
            </a>
            <?php
            }
    
        else if ($choixMenu[0] == false){?>   
            <div class="ui-block-a"   href="#"  id="bouton-home">
            </div>
            <?php
            } 

            ////////////////////////
            // Bouton CENTRAL //
            ////////////////////////
            
            if ($choixMenu[1] == false){
            	?>
            	    <div class="ui-block-b"  id="bouton-menu"  href="#"></div>
            	<?php
            }
            
			else {
            	
				// Utilisation des 3 "egal" pour qu'il soit du même type après transtypage
				if($choixMenu[1] === "tech"){
					
					if( $_SESSION['login_session'] === 1){
						 ?>
				         	<a class="ui-block-b"  data-role="button"  id="bouton-menu" href="index.php?page=techniciens">Tech</a>
				         <?php
					}
					else {
						?>
				         	<div class="ui-block-b">
                			</div>
				         <?php
					}
				}
				else  {
					?>
				        <a class="ui-block-b"  data-icon="grid" data-role="button"   id="bouton-menu"  href="index.php?page=menu&action=menu&id_client=<?php echo $choixMenu[3]; ?>">
				    	</a>
					<?php
				}
			}
			
			///////////////////////////////
			// Bouton DECONNEXION //
			//////////////////////////////
                        
            if ($choixMenu[2] != false) {?>   
            <a class="ui-block-c"  data-icon="forward" data-role="button"   id="bouton-auth" href="index.php?page=authentification">
            </a>
            <?php
            }
             
        else if ($choixMenu[2] != false){?>   
            <div class="ui-block-c"   id="bouton-auth">
            </div>
		    <?php
            } 
       ?>
       </div>
  <?php 
}


function menuInferieur($choixBouton) {
?>  
        <div class="ui-grid-b" style="height: 1.8em;" id="menu-bottom">
            <?php
            
            ///////////////////////////
            // Bouton SUPPRIMER //
            //////////////////////////
            
            if ($choixBouton[0] != false) { ?>
                <a class="ui-block-a" data-role="button" data-icon="delete"  id="bouton-suppr"
                    href="index.php?page=<?php echo $choixBouton[3]; ?>&action=s" >
                </a> 
                <?php
                }
                       
            if ($choixBouton[0] == false) { ?>   
                <div class="ui-block-a"  id="bouton-suppr">
                </div>
                <?php
                }

                
             /////////////////////////
             // Bouton MODIFIER //
             ////////////////////////
             
            if ($choixBouton[1] != false) {?>
                <a class="ui-block-b" data-role="button" data-icon="edit"  id="bouton-modif"
                    href="index.php?page=<?php echo $choixBouton[3]; ?>&action=m">
                </a>
                <?php
                }
                
            if ($choixBouton[1] == false) {?>   
                <div class="ui-block-b" id="bouton-modif">
                </div>
                <?php
                }

                
             /////////////////////////
             // Bouton AJOUTER //
             ////////////////////////
                
            if ($choixBouton[2] != false) { ?>
                <a class="ui-block-c" data-role="button" data-icon="plus" id="bouton-ajout"
                    href="index.php?page=<?php echo $choixBouton[3]; ?>&action=a" >
                </a>
                <?php
                }
                
            if ($choixBouton[2] == false) {?>   
                <div class="ui-block-c" id="bouton-ajout">
                </div>
                <?php
                }
                ?>
            </div>
        <?php
    }

 
function miniaturiser( $image_src , $image_dest = NULL , $max_size = 100, $expand = FALSE, $square = FALSE ) {
	
	if( !file_exists($image_src) ) return FALSE;

	// Récupére les infos de l'image
	$fileinfo = getimagesize($image_src);
	if( !$fileinfo ) return FALSE;

	$width     = $fileinfo[0];
	$height    = $fileinfo[1];
	$type_mime = $fileinfo['mime'];
	$type      = str_replace('image/', '', $type_mime);

	if( !$expand && max($width, $height)<=$max_size && (!$square || ($square && $width==$height) ) )
		{
		// L'image est plus petite que max_size
		if($image_dest)
			{
			return copy($image_src, $image_dest);
		}
		else
			{
			header('Content-Type: '. $type_mime);
			return (boolean) readfile($image_src);
		}
	}

	// Calcule les nouvelles dimensions
	$ratio = $width / $height;

	if( $square )
		{
		$new_width = $new_height = $max_size;

		if( $ratio > 1 )
			{
			// Paysage
			$src_y = 0;
			$src_x = round( ($width - $height) / 2 );

			$src_w = $src_h = $height;
		}
		else
			{
			// Portrait
			$src_x = 0;
			$src_y = round( ($height - $width) / 2 );

			$src_w = $src_h = $width;
		}
	}
	else
		{
		$src_x = $src_y = 0;
		$src_w = $width;
		$src_h = $height;

		if ( $ratio > 1 )
			{
			// Paysage
			$new_width  = $max_size;
			$new_height = round( $max_size / $ratio );
		}
		else
			{
			// Portrait
			$new_height = $max_size;
			$new_width  = round( $max_size * $ratio );
		}
	}

	// Ouvre l'image originale
	$func = 'imagecreatefrom' . $type;
	if( !function_exists($func) ) return FALSE;

	$image_src = $func($image_src);
	$new_image = imagecreatetruecolor($new_width,$new_height);

	// Gestion de la transparence pour les png
	if( $type=='png' )
		{
		imagealphablending($new_image,false);
		if( function_exists('imagesavealpha') )
				imagesavealpha($new_image,true);
	}

	// Gestion de la transparence pour les gif
	elseif( $type=='gif' && imagecolortransparent($image_src)>=0 )
	{
		$transparent_index = imagecolortransparent($image_src);
		$transparent_color = imagecolorsforindex($image_src, $transparent_index);
		$transparent_index = imagecolorallocate($new_image, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
		imagefill($new_image, 0, 0, $transparent_index);
		imagecolortransparent($new_image, $transparent_index);
	}

	// Redimensionnement de l'image
	imagecopyresampled(
		$new_image, $image_src,
		0, 0, $src_x, $src_y,
		$new_width, $new_height, $src_w, $src_h
		);

	// Enregistrement de l'image
	$func = 'image'. $type;
	if($image_dest)
		{
		$func($new_image, $image_dest);
	}
	else
		{
		header('Content-Type: '. $type_mime);
		$func($new_image);
	}

	// Libération de la mémoire
	imagedestroy($new_image);

	return TRUE;
}

// Clé sécurisé
function keygen() {
	
	return md5(uniqid(microtime(), TRUE));
	
}

function remplacer_cote($chaine) {
	
	$resultat = str_replace("'", "___", $chaine);
	
	return $resultat;
}

function de_remplacer_cote($chaine) {

	$resultat = str_replace("___", "'", $chaine);

	return $resultat;
}

